package com.kiwilss.aopdemo.ui.viewmodel

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelProviders
import com.kiwilss.aopdemo.R
import com.kiwilss.aopdemo.ui.WorkUtil
import kotlinx.android.synthetic.main.activity_viewmodel.*

/**
 * @author : Administrator
 * e-mail : kiwilss@163.com
 * time   : 2021/02/01
 *  desc   :https://blog.csdn.net/Alexwll/article/details/82459614
 *  https://blog.csdn.net/huangliniqng/article/details/106252572
 */
class ViewModelActivity: AppCompatActivity(R.layout.activity_viewmodel) {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        lifecycle.addObserver(WorkUtil())

        val emptyModel = ViewModelProviders.of(this)[EmptyModel::class.java]
//        ViewModelProvider(this)[EmptyModel::class.java]

        tvViewModelShow.text = emptyModel.textName

        btnViewModelChange.setOnClickListener {
            emptyModel.textName = "change after empty model"
            tvViewModelShow.text = emptyModel.textName
        }




    }
}